import {getGoodsCatelog,getMianData,getSubCatelog,getGoodsSecondListXCX} from '../../Tools/HTTPOpertion.js';
Component({
  data:{
    select:0,
    select2:0,
    list1:[],
    list11:[],
    list2:[],
    list3:[],
    classify1:{name:'全部',id:0,index:0},
    classify2:{name:'排序',id:0,index:0},
    classify3:{name:'配送方式',id:0,index:0}
  },
  properties: {
     mainlist:{
       type:Array,
       value:[]
     }
  },
  ready:function(){
    this.getGoodsCatelog()
  },
  methods: {
    changeData:function(newVal,oldVal){
      this.setData({Msg:newVal})
    },
    // 获取 全部分类 中数据
    getGoodsCatelog: function (e) {
      const that = this;
      getGoodsCatelog({}).then(function (result) {
        var temp = [{ name: "全部", id: 0 }].concat(result.data);
        that.setData({
          list1: temp
        });
      })
    },
    choose:function(e){
      const type=e.currentTarget.dataset.type;
      const originval=this.data.select;
      this.setData({
         select:originval==type?0:type
      })
      this.triggerEvent('chooseClassify',{select:this.data.select})
    },
    //分类列表筛选点击
    PopupBoxLeftChoose: function (e) {
      const self=this,id=e.currentTarget.dataset.id,index=e.currentTarget.dataset.index;
      if(index==0){
        this.setData({
          classify1: e.currentTarget.dataset,
          select:0
        })
        this.getData()
        return false;
      }
      const config={ intPara2: wx.getStorageSync("city"), level: wx.getStorageSync("level"), latitude: wx.getStorageSync("latitude"), longitude: wx.getStorageSync("longitude"), intPara: id }
      getSubCatelog(config).then(function (result) {
        var temp = [{ name: "全部", id: 0 }].concat(result.data.list);
        self.setData({
          list11: temp,
          select2:index
        });
      })
    },
    //分类二级列表筛选点击**
    PopupBoxLeft: function (e) {
      if(e.currentTarget.dataset.index==0){
        this.setData({
          classify1:this.data.mainlist[this.data.select2],
          select:0
        })
        this.getData()
        return false;
      }
      this.setData({
        classify1: e.currentTarget.dataset,
        select:0
      })
      this.getData()
   },
   //排序筛选
   PopupBoxRight: function (e) {
    this.setData({
      select: 0,
      classify2:e.currentTarget.dataset
    })
    this.getData()
   },
   //配送方式
   PopupBoxPeisong:function (e) {
    this.setData({
      select: 0,
      classify3:e.currentTarget.dataset
    })
    this.getData()
  },
  getData:function() {
    const config={intPara:this.data.classify1.id,intPara2:this.data.classify2.id,intPara4:this.data.classify3.id}
    this.triggerEvent('loadData',config)
  }
 }
})
